package com.sc.nft.service;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.dao.GetMallOrderGrossProfitDTO;
import com.sc.nft.entity.MallOrder;
import com.sc.nft.entity.MallOrderStatusLog;
import com.sc.nft.entity.RefundRecordVO;
import com.sc.nft.entity.UserInfo;
import com.sc.nft.entity.dto.BatchDeliverDTO;
import com.sc.nft.entity.vo.DistributionOrderVO;
import com.sc.nft.entity.vo.ExportOrderListVO;
import com.sc.nft.entity.vo.mall.*;
import com.sc.nft.enums.*;
import com.sc.nft.enums.task.ActivityTypeEnum;
import com.sc.nft.exception.GlobalException;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Date;
import java.util.List;

/**
 * ip商城订单主表服务接口
 *
 * @author Sun
 * @description 由 Mybatisplus Code Generator 创建
 * @since 2023-05-09 10:46:38
 */
public interface MallOrderService {

    /**
     * 订单确认页
     *
     * @param activityId
     * @param specsId
     * @param count
     * @param user
     * @return
     */
    OrderConfirmVO orderConfirm(Long activityId, Long specsId, Integer count, UserInfo user, Long shareTeamId,Long groupId);

    /**
     * 订单确认页
     *
     * @param orderNo
     * @return
     */
    OrderConfirmByOrderNoVO orderConfirmByOrderId(String orderNo);

    /**
     * 创建订单
     *
     * @param activityId 营销活动id
     * @param specsId    规格id
     * @param count      购买数量
     * @param user       用户信息
     * @return
     */
    CreateMallOrderVO createMallOrder(Long activityId, Long specsId, Integer count, UserInfo user, Long mallDeliveryAddressId, String dealPwd, String apiChargeAccount, Long userCouponsId, Long shareTeamId,Long groupId);


    /**
     * 计算价格
     *
     * @param activityId
     * @param specsId
     * @param count
     * @param user
     * @return
     */
    ProductValuationVO productValuation(Long activityId, Long specsId, Integer count, UserInfo user, Long shareTeamId);

    /**
     * 分页查询订单
     *
     * @param user
     * @param activityType
     * @param queryStatus
     * @param pageNo
     * @param pageSize
     * @return
     */
    Page<PageMallOrderVO> pageMallOrder(Long userId, ActivityTypeEnum activityType, Integer queryStatus, Integer pageNo, Integer pageSize, SourceEnum sourceEnum, Long wxMiniUserId);

    /**
     * 分页查询推广订单
     *
     * @param user
     * @param incomeStatus
     * @param pageNo
     * @param pageSize
     * @return
     */
    Page<PageMallPopularizeOrderVO> pageMallPopularizeOrder(UserInfo user, Integer incomeStatus, Integer pageNo, Integer pageSize);

    /**
     * 订单详情
     *
     * @param userId
     * @param id
     * @return
     */
    MallOrderDetailsVO mallOrderDetails(Long userId, Long id, SourceEnum source, Long wxMiniUserId);


    /**
     * 修改订单状态 并添加日志
     */
    void updateStatusById(Long id, MallOrderStatusEnum status);

    /**
     * 获取超时订单
     *
     * @return
     */
    List<MallOrder> getTimeOutMallOrder();

    /**
     * 关闭订单
     *
     * @param order
     */
    Boolean autoCloseOrder(MallOrder order) throws GlobalException;

    /**
     * 手动取消订单
     *
     * @param orderId
     */
    void cancelOrderById(Long orderId, Long userId, SourceEnum source, Long wxMiniUserId) throws GlobalException;

    /**
     * 已发货订单列表
     *
     * @return
     */
    List<MallOrder> getAutoConfirmMallOrder(Integer day);

    /**
     * 自动确认收货
     *
     * @param order
     * @throws GlobalException
     */
    void autoConfirmOrder(MallOrder order, Integer confirmDay) throws GlobalException;


    /**
     * 手动确认收货
     *
     * @param orderId
     */
    void confirmOrderById(Long orderId, Long userId, SourceEnum source, Long wxMiniUserId) throws GlobalException;

    /**
     * 获取订单
     *
     * @param orderId
     * @return
     */
    MallOrder getById(Long orderId);

    /**
     * 获取订单
     *
     * @param orderNo
     * @return
     */
    MallOrder getByOrderNo(String orderNo);

    /**
     * 获取退款原因
     */
    RefundInfoVO getRefundReason(Long id, Long orderProductId);

    /**
     * 退款计价
     *
     * @param id
     * @param orderProductId
     * @param count
     * @return
     */
    RefundValuationVO getRefundValuation(Long id, Long orderProductId, Integer count);

    /**
     * 售后申请提交
     *
     * @param id
     * @param orderProductId
     * @param count
     * @param refundReason
     * @param refundType
     * @param imgUrl
     */
    Long applyRefund(Long id, Long orderProductId, Integer count, RefundReasonEnum refundReason, MallOrderRefundTypeEnum refundType, String imgUrl, String description, String contactNumber);

    /**
     * 售后详情
     *
     * @param id
     * @param orderProductId
     * @return
     */
    RefundDetailsVO refundDetails(Long id, Long orderProductId);

    /**
     * 取消售后
     *
     * @param id
     * @param orderProductId
     */
    void cancelApplyRefund(Long id, Long orderProductId);

    /**
     * 退款记录
     *
     * @param id
     * @return
     */
    List<RefundRecordVO> refundRecord(Long id);

    /**
     * 后台查询订单列表
     *
     * @param activityType
     * @param orderNo
     * @param beginTime
     * @param endTime
     * @param payBeginTime
     * @param payEndTime
     * @param productName
     * @param status
     * @param payType
     * @param isRefund
     * @param userTel
     * @param pageNo
     * @param pageSize
     * @return
     */
    Page<AdminMallPageOrderVO> adminPageOrder(ActivityTypeEnum activityType, String orderNo, Date beginTime, Date endTime, Date payBeginTime, Date payEndTime, String productName, Integer status, Integer payType, Integer isRefund, String userTel, Integer pageNo, Integer pageSize, Long supplierId, String categoryName, SourceEnum orderSource);


    /**
     * 后台订单详情
     *
     * @param orderId
     * @return
     */
    AdminOrderDetailsVO adminOrderDetails(Long orderId);

    /**
     * 后台售后列表
     *
     * @param orderNo
     * @param userTel
     * @param refundStatus
     * @return
     */
    @Deprecated
    Page<AdminPageRefundOrderVO> adminPageRefundOrder(String orderNo, String userTel, Integer refundStatus, Integer pageNo, Integer pageSize, Long supplierId);

    /**
     * 后台售后详情
     *
     * @param orderId
     * @return
     */
    AdminRefundDetailsVO adminRefundDetails(Long orderId);

    /**
     * 后台售后审核通过 退钱
     *
     * @param orderId
     */
    void approvalRefundSuccess(Long orderId, Long orderProductId, String ip);

    /**
     * 发货
     *
     * @param deliveryNo
     */
    void ship(MallOrder order, String deliveryNo, String deliveryName);

    /**
     * 修改订单的收益人
     *
     * @param pushStraightIncomeUserId
     * @param pushBetweenIncomeUserId
     * @param cityServerIncomeUserId
     * @return
     */
    Boolean updateIncomeUserId(Long id, Long pushStraightIncomeUserId, Long pushBetweenIncomeUserId, Long cityServerIncomeUserId);

    /**
     * 后置逻辑
     *
     * @param mallOrderStatusLog
     * @param order
     */
    void postLogic(MallOrderStatusLog mallOrderStatusLog, MallOrder order);

    /**
     * 小程序订单后置逻辑
     *
     * @param mallOrderStatusLog
     * @param order
     */
    void miniPostLogic(MallOrderStatusLog mallOrderStatusLog, MallOrder order);

    /**
     * 获取某个订单的总利润(排除权益礼包后的利润)
     */
    GetMallOrderGrossProfitDTO getGrossProfitByOrderId(MallOrder order);

    /**
     * 编辑备注
     *
     * @param id
     * @param adminNote
     */
    void editAdminNote(Long id, String adminNote);

    /**
     * 给前端返回导出的订单数据
     *
     * @return
     */
    List<ExportOrderListVO> exportOrderList(ActivityTypeEnum type);

    /**
     * 批量发货
     *
     * @param file
     * @return
     */
    List<BatchDeliverDTO> batchDeliver(MultipartFile file) throws IOException;

    /**
     * 通过售后状态查询售后单
     *
     * @param mallOrderRefundStatusEnum
     * @return
     */
    List<MallOrder> getByRefundStatus(MallOrderRefundStatusEnum mallOrderRefundStatusEnum);

    /**
     * 获取订单列表
     *
     * @param ids
     * @return
     */
    List<MallOrder> getByIds(List<Long> ids, Long wxMiniUserId);

    Page<DistributionOrderVO> getDistributionOrderVOAdminPage(String orderNO, Date startTime, Date endTime, String miniUserTel,
                                                              MallOrderStatusEnum status, MallOrderIncomeTypeEnum incomeStatus, Integer pageNo, Integer pageSize);

    /**
     * 更换收货地址
     * @param orderId
     * @param mallDeliveryAddressId
     * @param userId
     * @param source
     * @param wxMiniUserId
     * @return
     */
    UpdateMallDeliveryAddressVO updateMallDeliveryAddress(Long orderId, Long mallDeliveryAddressId, Long userId, SourceEnum source, Long wxMiniUserId);

    /**
     * 获取当前订单地址
     * @param orderId
     * @return
     */
    MallOrderDeliveryAddressVO orderNowAddress(Long orderId,Long userId, SourceEnum source, Long wxMiniUserId);
}
